<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input id="txt" />
    <script>
        // 防抖 最后一次才会执行 debounce
        txt.oninput = debounce(function () {
            console.log(123);
        })

        function debounce(fn) {
            return function () {
                clearTimeout(window.timer)
                window.timer = setTimeout(() => {
                    fn()
                }, 500)
            }
        }
        // 节流 一定时间内只做一次 throttle
    </script>
</body>

</html>